package javaUncompress;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;

public class JavaUncompress
{
    private String outFilename;
    
    /**
     * This method uncompress the file
     * 
     * @param file
     *            file location
     */
    
    public JavaUncompress(String file)
    {
        
        try
        {
            // To Uncompress GZip File Contents we need to open the gzip
            // file.....
            if (file == null)
            {
                System.out.println("No file exists");
            }
            else
            {
                String inFilename = file;
                System.out
                        .println("Opening the gzip file.......................... :  opened");
                
                GZIPInputStream gzipInputStream = null;
                FileInputStream fileInputStream = null;
                gzipInputStream = new GZIPInputStream(new FileInputStream(
                        inFilename));
                
                System.out
                        .println("Opening the output file............. : opened");
                
                outFilename = inFilename + ".svg";
                
                OutputStream out = new FileOutputStream(outFilename);
                
                System.out
                        .println("Transferring bytes from the compressed file to the output "
                                +
                                "file........:    Transfer successful");
                byte[] buf = new byte[1024]; // size can be
                
                int len;
                while ((len = gzipInputStream.read(buf)) > 0)
                {
                    out.write(buf, 0, len);
                }
                System.out.println("The file and stream is ......closing...." +
                        "...... : closed");
                
                gzipInputStream.close();
                out.close();
            }
        }
        catch (IOException e)
        {
            System.out.println("Exception has been thrown" + e);
        }
    }
    
    public String getOutFilename()
    {
        return outFilename;
    }
    
    public void setOutFilename(String outFilename)
    {
        this.outFilename = outFilename;
    }
    
}
